#ifndef _NET_INFOM_H_
#define _NET_INFOM_H_

// #if defined(_WIN32) || defined(_WIN64)
#if 0
#include <winsock2.h>   //-lwsock32
#include <ws2tcpip.h>
#else
#include <arpa/inet.h>
#include <net/if.h>
#define USE_IF_ADDR 1

int get_local_ip(const char* eth_name ,char* ip);
int get_local_gw(const char* eth_name ,char* gw);
int get_local_netmask(const char* eth_name ,char* netmask);
int get_ip_by_gw(const char* gw,char *ip);
#if !USE_IF_ADDR
int get_local_hwaddr(const char* eth_name ,char* hwaddr);
#endif

struct NetFlowInfo
{
    long rcv_rates;     // 接收流量计数
    long tx_rates;      // 发送流量计数
    long rcv_speed;     // 接收速率 Byte/s
    long tx_speed;      // 发送速率 Byte/s
};

struct NetBaseInfo {
    char name[128];
    unsigned int ifa_flags;     // ifa->ifa_flags
    unsigned int sa_family;     // ifa->ifa_addr->sa_family
    char ip[INET6_ADDRSTRLEN];  
    char netmask[20];
    // char broadaddr[20];
    char dstaddr[INET6_ADDRSTRLEN];
    struct NetFlowInfo flow_info;
};

struct NetInfo {
    int net_info_num;
    // unsigned int filter;
    struct NetBaseInfo *ninfo; 
};

/**
 * @brief 网卡信息初始化
 * 
 * @param nif 网卡数据
 * @param filter 过滤器，默认设置0或0xffffffff，具体查看net/if.h中enum net_device_flags内容
 * @return int 0 成功 -1 失败
 * @note not 
 */
int NetInfoInit(struct NetInfo *nif, unsigned int flag_filter);
int NetInfoDeinit(struct NetInfo *nif);
int GetNetSpeed(struct NetInfo *nif, int cross_time_ms);

#endif

#endif

